<template>
  <div>
    <div class="toggle-button" @click="changeCollapse">|||</div>
    <el-menu
      style="text-align: left;background-color: #6aD;"
      background-color="#6aD"
      active-text-color="#fff"
      text-color="#000"
      :default-active="activeIndex"
      class="el-menu-vertical-demo"
      @open="handleOpen"
      @close="handleClose"
      :collapse="isCollapse"
      
    >
      <el-menu-item :index="item.path" v-for="item in menuList" :key="item.id" @click="ophenMenuItem(item)">
        <i :class="item.icon"></i>
        <span slot="title">{{ item.name }}</span>
      </el-menu-item>
    </el-menu>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // activeIndex:"/admin/score",
      isCollapse: false,
      menuList: [
        {
          id: 1,
          path: "/admin/score",
          name: "成绩管理",
          icon: "el-icon-notebook-2",
        },
        {
          id: 2,
          path: "/admin/question",
          name: "试题管理",
          icon: "el-icon-tickets",
        },
        {
          id: 3,
          path: "/admin/search",
          name: "查阅试卷",
          icon: "el-icon-edit-outline",
        },
        {
          id: 4,
          path: "/admin/student",
          name: "考生管理",
          icon: "el-icon-user",
        },
        {
          id: 5,
          path: "/admin/maintain",
          name: "管理员账号维护",
          icon: "el-icon-user-solid",
        },
        {
          id: 6,
          path: "/admin/errorhandling",
          name: "学生宕机处理",
          icon: "el-icon-menu",
        },
      ],
    };
  },

  methods: {
    
    ophenMenuItem(item){
      console.log(item);
      this.$store.commit("addTab",item)
      // this.$router.push(item.path)

    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    changeCollapse() {
      this.isCollapse = !this.isCollapse;
      this.$parent.$data.flag = this.isCollapse;
    },
  },
  computed:{
    activeIndex(){
      return this.$store.state.tabList[this.$store.state.tabIndex].path
    }
  }
};
</script>

<style lang="less" scoped>
.el-menu {
  // transition:width .5s,
  border: none;
}
.toggle-button{
  background-color: #6aD;
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px; //宽度自己掌握
  height: 100%;
}
.el-menu-item i{
  color: #333;
}
</style>